package com.css.security.app.social;

import com.css.security.core.config.CssSpringSocialConfigurer;
import com.css.common.security.constant.SecurityConstants;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;

/**
 * SpringSocialConfigurerPostProcessor
 * 实现BeanPostProcessor接口,spring容器中 所有的bean 初始化开始和结束都会执行下面方法
 *
 * @author hanyx
 * @date 2019/04/17
 */
public class SpringSocialConfigurerPostProcessor implements BeanPostProcessor {

    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        if (StringUtils.equals(beanName,"cssSocialSecurityConfig")) {
            CssSpringSocialConfigurer cssSpringSocialConfigurer = (CssSpringSocialConfigurer) bean;
            cssSpringSocialConfigurer.signupUrl(SecurityConstants.DEFAULT_SOCIAL_USER_INFO_URL);
            return cssSpringSocialConfigurer;
        }
        return bean;
    }
}
